#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "EmailRecover.h"
#include "EmailParse.h"

int main()
{
    FILE* fp = NULL;
    int vi = 0,vj = 0;
	   int pos = 0;
    linelist * plist = NULL;
    mailhead* mhead = NULL;
	   char bufline[256] = "\0";
    char * buffer = NULL;
    buffer = (char *)malloc(3000*sizeof(char));
    fp = fopen("C:\\Users\\shrine\\Desktop\\test1.txt","r");
    if(fp == NULL)
    {
        printf("cannot open this file!");
        system("pause");
        return 1;
    }
    while(!feof(fp))
    {
        buffer[vi] = fgetc(fp); 
        vi++;
    }
    printf("vi is %d\n",vi);
    buffer[vi] = '\0';
    printf("%s\n",buffer);
    mhead = InitMailhead();
    plist = LoadMailline(buffer,vi);
    ParseMime(plist,mhead);
    PrintfMailhead(mhead);
    ClearMailhead(mhead);
    //Printflinelist(plist);
    Deletelinelist(plist);
    free(buffer);
    buffer = NULL;
    system("pause");
    return 0;
}